from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-18 14:07:05.790998
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 18, Feb, 2022
Time: 14:07:10
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1636
Nobs: 571.000 HQIC: -48.5815
Log likelihood: 6744.42 FPE: 6.09856e-22
AIC: -48.8489 Det(Omega_mle): 5.21635e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.346591 0.068629 5.050 0.000
L1.Burgenland 0.106300 0.041707 2.549 0.011
L1.Kärnten -0.110713 0.021712 -5.099 0.000
L1.Niederösterreich 0.187471 0.086963 2.156 0.031
L1.Oberösterreich 0.133110 0.086027 1.547 0.122
L1.Salzburg 0.254784 0.044147 5.771 0.000
L1.Steiermark 0.036929 0.058264 0.634 0.526
L1.Tirol 0.100052 0.047006 2.128 0.033
L1.Vorarlberg -0.068860 0.041462 -1.661 0.097
L1.Wien 0.021158 0.076477 0.277 0.782
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053035 0.148040 0.358 0.720
L1.Burgenland -0.038048 0.089966 -0.423 0.672
L1.Kärnten 0.041355 0.046836 0.883 0.377
L1.Niederösterreich -0.204760 0.187590 -1.092 0.275
L1.Oberösterreich 0.461146 0.185569 2.485 0.013
L1.Salzburg 0.282105 0.095231 2.962 0.003
L1.Steiermark 0.113601 0.125682 0.904 0.366
L1.Tirol 0.304611 0.101397 3.004 0.003
L1.Vorarlberg 0.025368 0.089439 0.284 0.777
L1.Wien -0.028952 0.164970 -0.175 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199852 0.035024 5.706 0.000
L1.Burgenland 0.088950 0.021285 4.179 0.000
L1.Kärnten -0.007391 0.011081 -0.667 0.505
L1.Niederösterreich 0.238770 0.044381 5.380 0.000
L1.Oberösterreich 0.162470 0.043903 3.701 0.000
L1.Salzburg 0.039880 0.022530 1.770 0.077
L1.Steiermark 0.026579 0.029735 0.894 0.371
L1.Tirol 0.082009 0.023989 3.419 0.001
L1.Vorarlberg 0.053819 0.021160 2.543 0.011
L1.Wien 0.117121 0.039030 3.001 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120982 0.034976 3.459 0.001
L1.Burgenland 0.043433 0.021255 2.043 0.041
L1.Kärnten -0.013093 0.011065 -1.183 0.237
L1.Niederösterreich 0.168769 0.044319 3.808 0.000
L1.Oberösterreich 0.337129 0.043842 7.690 0.000
L1.Salzburg 0.100433 0.022499 4.464 0.000
L1.Steiermark 0.110671 0.029693 3.727 0.000
L1.Tirol 0.090410 0.023956 3.774 0.000
L1.Vorarlberg 0.060896 0.021131 2.882 0.004
L1.Wien -0.019854 0.038976 -0.509 0.610
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121763 0.065935 1.847 0.065
L1.Burgenland -0.046334 0.040070 -1.156 0.248
L1.Kärnten -0.045149 0.020860 -2.164 0.030
L1.Niederösterreich 0.133952 0.083550 1.603 0.109
L1.Oberösterreich 0.166438 0.082650 2.014 0.044
L1.Salzburg 0.284304 0.042415 6.703 0.000
L1.Steiermark 0.057920 0.055977 1.035 0.301
L1.Tirol 0.156108 0.045161 3.457 0.001
L1.Vorarlberg 0.097869 0.039835 2.457 0.014
L1.Wien 0.075932 0.073476 1.033 0.301
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080939 0.051375 1.575 0.115
L1.Burgenland 0.025598 0.031221 0.820 0.412
L1.Kärnten 0.053461 0.016254 3.289 0.001
L1.Niederösterreich 0.188783 0.065100 2.900 0.004
L1.Oberösterreich 0.329523 0.064398 5.117 0.000
L1.Salzburg 0.034306 0.033048 1.038 0.299
L1.Steiermark 0.005860 0.043616 0.134 0.893
L1.Tirol 0.120355 0.035188 3.420 0.001
L1.Vorarlberg 0.066249 0.031038 2.134 0.033
L1.Wien 0.096768 0.057250 1.690 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169655 0.062086 2.733 0.006
L1.Burgenland 0.004317 0.037731 0.114 0.909
L1.Kärnten -0.065846 0.019643 -3.352 0.001
L1.Niederösterreich -0.108780 0.078673 -1.383 0.167
L1.Oberösterreich 0.209094 0.077826 2.687 0.007
L1.Salzburg 0.053707 0.039939 1.345 0.179
L1.Steiermark 0.249258 0.052710 4.729 0.000
L1.Tirol 0.499667 0.042525 11.750 0.000
L1.Vorarlberg 0.065218 0.037510 1.739 0.082
L1.Wien -0.073158 0.069187 -1.057 0.290
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160763 0.068874 2.334 0.020
L1.Burgenland -0.003815 0.041855 -0.091 0.927
L1.Kärnten 0.062749 0.021790 2.880 0.004
L1.Niederösterreich 0.166440 0.087274 1.907 0.057
L1.Oberösterreich -0.055191 0.086333 -0.639 0.523
L1.Salzburg 0.207120 0.044305 4.675 0.000
L1.Steiermark 0.139227 0.058472 2.381 0.017
L1.Tirol 0.055862 0.047173 1.184 0.236
L1.Vorarlberg 0.146661 0.041610 3.525 0.000
L1.Wien 0.123343 0.076750 1.607 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394296 0.040379 9.765 0.000
L1.Burgenland -0.003194 0.024539 -0.130 0.896
L1.Kärnten -0.021382 0.012775 -1.674 0.094
L1.Niederösterreich 0.200464 0.051167 3.918 0.000
L1.Oberösterreich 0.229543 0.050616 4.535 0.000
L1.Salzburg 0.037307 0.025975 1.436 0.151
L1.Steiermark -0.017176 0.034281 -0.501 0.616
L1.Tirol 0.091139 0.027657 3.295 0.001
L1.Vorarlberg 0.050895 0.024395 2.086 0.037
L1.Wien 0.041183 0.044997 0.915 0.360
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036353 0.102118 0.169336 0.137143 0.095843 0.081657 0.032804 0.210464
Kärnten 0.036353 1.000000 -0.027797 0.132362 0.048290 0.085516 0.444082 -0.067256 0.089221
Niederösterreich 0.102118 -0.027797 1.000000 0.309869 0.118804 0.269312 0.065706 0.151876 0.286996
Oberösterreich 0.169336 0.132362 0.309869 1.000000 0.214839 0.293655 0.167636 0.135983 0.234222
Salzburg 0.137143 0.048290 0.118804 0.214839 1.000000 0.124348 0.091311 0.105113 0.123923
Steiermark 0.095843 0.085516 0.269312 0.293655 0.124348 1.000000 0.134212 0.106064 0.031458
Tirol 0.081657 0.444082 0.065706 0.167636 0.091311 0.134212 1.000000 0.062682 0.151722
Vorarlberg 0.032804 -0.067256 0.151876 0.135983 0.105113 0.106064 0.062682 1.000000 -0.005449
Wien 0.210464 0.089221 0.286996 0.234222 0.123923 0.031458 0.151722 -0.005449 1.000000